extends ../layout

block content
  h2
    i.fab.fa-github.fa-sm.me-2
    | GitHub API

  .btn-group.d-flex(role='group')
    a.btn.btn-primary.w-100(href='https://docs.github.com/get-started', target='_blank')
      i.far.fa-check-square.fa-sm.me-2
      | Getting Started
    a.btn.btn-primary.w-100(href='http://developer.github.com/v3/', target='_blank')
      i.far.fa-file-alt.fa-sm.me-2
      | Documentation
  br
  // Your GitHub Profile Section
  if userInfo
    .card.text-white.bg-success.mb-4
      .card-header
        h6.panel-title.mb-0 Your GitHub Profile
      .card-body.text-dark.bg-white
        .row
          .col-3
            img.img-thumbnail(src=userInfo.avatar_url, alt='User Avatar')
          .col-9
            h4 #{ userInfo.name || userInfo.login }
            ul.list-unstyled
              li
                strong Username:
                |
                | #{ userInfo.login }
              li
                strong Followers:
                |
                | #{ userInfo.followers }
              li
                strong Public Repositories:
                |
                | #{ userInfo.public_repos }
              li
                strong GitHub Profile:
                |
                |
                a(href=userInfo.html_url, target='_blank') #{ userInfo.html_url }

        if userRepos.length > 0
          hr
          h5 My Repositories (up to #{ limit })
          ul.list-unstyled
            each repo in userRepos
              li
                a(href=repo.html_url, target='_blank') #{ repo.name }
                |
                | - #{ repo.description || 'No description provided.' }

        if userEvents.length > 0
          hr
          h5 Recent Activity (up to #{ limit })
          ul.list-unstyled
            each event in userEvents
              if event.type === 'PullRequestEvent'
                li
                  | Pull request #{ event.payload.action }
                  |
                  a(href=event.payload.pull_request.html_url, target='_blank') #{ event.payload.pull_request.title || `#${event.payload.number}` }
                  |
                  | in
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
              else if event.type === 'PushEvent'
                li
                  | Pushed to
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
                  |
                  | (#{ event.payload.ref.replace('refs/heads/', '') })
              else if event.type === 'IssuesEvent'
                li
                  | Issue #{ event.payload.action }
                  |
                  a(href=event.payload.issue.html_url, target='_blank') #{ event.payload.issue.title || `#${event.payload.issue.number}` }
                  |
                  | in
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
              else if event.type === 'IssueCommentEvent'
                li
                  | Commented on issue
                  |
                  a(href=event.payload.issue.html_url, target='_blank') #{ event.payload.issue.title || `#${event.payload.issue.number}` }
                  |
                  | in
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
              else if event.type === 'CreateEvent'
                li
                  | Created #{ event.payload.ref_type }
                  |
                  if event.payload.ref
                    | #{ event.payload.ref }
                  |
                  | in
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
              else if event.type === 'DeleteEvent'
                li
                  | Deleted #{ event.payload.ref_type }
                  |
                  | #{ event.payload.ref }
                  |
                  | in
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
              else if event.type === 'ForkEvent'
                li
                  | Forked
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }
              else if event.type === 'WatchEvent'
                li
                  | #{ event.payload.action === 'started' ? 'Starred' : event.payload.action }
                  |
                  a(href=event.repo.url.replace('api.github.com/repos', 'github.com'), target='_blank') #{ event.repo.name }

  else
    .alert.alert-warning
      if authFailure === 'NotLoggedIn'
        | Please log in to access your GitHub profile information.
      else if authFailure === 'NotGitHubAuthorized'
        | You are logged in but have not linked your GitHub account.
        |
        a(href='/auth/github') Link your GitHub account
        |
        | to access your GitHub profile information.
      else
        | Unable to fetch user information. Please ensure you are authenticated.

  // Repository Lookup Example Section
  .card.text-white.bg-primary.mb-4
    .card-header
      h6.panel-title.mb-0 Repository Lookup Example
    .card-body.text-dark.bg-white
      .row
        .col-8
          h4
            a(href=repo.html_url, target='_blank') #{ repo.name }
          p= repo.description
          ul.list-inline
            li.list-inline-item
              i.far.fa-star.fa-sm.me-2
              | Stars: #{ repo.stargazers_count }
            li.list-inline-item
              i.fas.fa-code-branch.fa-sm.me-2
              | Forks: #{ repo.forks_count }
            li.list-inline-item
              i.far.fa-eye-slash.fa-sm.me-2
              | Watchers: #{ repo.watchers_count }
            li.list-inline-item
              i.fas.fa-book.fa-sm.me-2
              | License: #{ repo.license ? repo.license.name : 'None' }
            li.list-inline-item
              i.far.fa-eye.fa-sm.me-2
              | Visibility: #{ repo.visibility }
            li.list-inline-item
              i.fas.fa-exclamation-circle.fa-sm.me-2
              | Open Issues: #{ repo.open_issues_count }

          strong Topics:
          if repo.topics.length > 0
            each topic in repo.topics
              span.badge.badge-secondary= topic
          else
            | None
          br
          strong Wiki:
          | #{ repo.has_wiki ? 'Enabled' : 'N/A' }

          if repoStargazers.length > 0
            hr
            h5 Stargazers (up to #{ limit })
            ul.list-inline
              each stargazer in repoStargazers
                li.list-inline-item
                  a(href=stargazer.html_url, target='_blank')
                    img.img-thumbnail(src=stargazer.avatar_url, alt='Stargazer Avatar', style='width: 50px; height: 50px')
